﻿using System.Diagnostics;
using System.Windows.Media.Media3D;
using LFSRecord2.Misc;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionKeyFrameBezierChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public int KeyFrameIndex { get; set; }
        public Vector3D BezierControlInOffset { get; set; }
        public Vector3D BezierControlOutOffset { get; set; }

        public UserActionKeyFrameBezierChanged()
        {
            Action = UserActionTypes.KeyFrameBezierChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a KeyFrameBezierChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while undoing kfBezierAction");
            }
            CustomPoint3DKeyFrame kfp = (CustomPoint3DKeyFrame)LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex];
            kfp.BezierControlIn -= BezierControlInOffset;
            kfp.BezierControlOut -= BezierControlOutOffset;
            kfp.OnPropertyChanged("BezierControl");
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a KeyFrameBezierChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while redoing kfBezierAction");
            }
            CustomPoint3DKeyFrame kfp = (CustomPoint3DKeyFrame)LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex];
            kfp.BezierControlIn += BezierControlInOffset;
            kfp.BezierControlOut += BezierControlOutOffset;
            kfp.OnPropertyChanged("BezierControl");
        }
    }
}
